package st.learnopengl.apps.assets

import gln.TextureTarget
import gln.identifiers.GlProgram
import gln.identifiers.GlTexture
import st.learnopengl.common.GLUT
import st.learnopengl.common.Resource
import org.lwjgl.opengl.GL13C.GL_TEXTURE0
import org.lwjgl.opengl.GL13C.glActiveTexture


class Texture(val path: String, val index: Int) {

    private var texture: GlTexture? = null

    var name: String = "texture1"

    fun build() {
        texture = GLUT.loadTexture(Resource.ModelRoot + path)
    }


    fun bind(program: GlProgram) {
        texture!!.bind(TextureTarget._2D)
        glActiveTexture(GL_TEXTURE0 + index)

        program.programUniform(program.getUniformLocation(name), index)
    }


    fun unbind() {
        texture!!.unbind(TextureTarget._2D)
    }
}